package cn.talk.socket.service;

import java.io.IOException;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;

public class Client {

    private Socket socket;

    private String id;

    public List<String> messageList = new ArrayList<>();

    public Client() throws IOException {
        socket = new Socket("127.0.0.1", 9999);
        new Thread(new Client_listen(socket, this)).start();
    }

    public void send(String sendId, String message) throws IOException {
        ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
        oos.writeObject(this.id + "-" + message + "-" + sendId);
        oos.flush();
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }
}
